package com.yang.design.structure.proxy.statics;

/**
 * 代理类,静态代理对象：UserDaoProxy 需要实现和目标类实现同样的IUserDao接口
 */
public class UserDaoProxy implements IUserDao {
    //内部含有对真实主题的引用,多态，对应的接口
    private  IUserDao target;

    //调用代理类，通过构造方法传入具体的目标类，即目标类
    public UserDaoProxy(IUserDao target) {
        this.target = target;
    }


    //功能扩展
    void preMethod(){
        System.out.println("开启事务");
    }
    //功能扩展
    void postMethod(){
        System.out.println("关闭事务");
    }

    @Override
    public boolean save(String userName) {
        preMethod();
        boolean save = target.save(userName);
        postMethod();
        return save;
    }
}
